package com.situ.stl.dao;

import com.situ.stl.entity.Coach;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/** 
 * Dao层 - 教练
 */
@Mapper 
public interface CoachMapper{

    /** 
     * Insert
     */
    @Insert( value = "insert into `coach` ( `name`, `phone`, `wechat`, `recomm`, `photo`) value ( #{name}, #{phone}, #{wechat}, #{recomm}, #{photo})") 
    @Options( useGeneratedKeys = true, keyColumn = "id", keyProperty = "id") 
    int insert( Coach coach) ;

    /** 
     * Delete
     */
    @Delete( value = "delete from `coach` where `id` = #{id}") 
    int delete( Integer id) ;

    /** 
     * Update
     */
    @Update( value = {
        "<script>",
        "update `coach`",
        "<set>",
        "<if test='name!=null'> `name` = #{name},</if>",
        "<if test='phone!=null'> `phone` = #{phone},</if>",
        " `wechat` = #{wechat},",
        " `recomm` = #{recomm},",
        " `photo` = #{photo},",
        "</set>",
        " where `id` = #{id}",
        "</script>"}) 
    int update( Coach coach) ;

    /** 
     * Select All
     */
    @Select( value = "select * from `coach`") 
    @Results( value = {
        @Result( column = "id", property = "id", id = true),
        @Result( column = "name", property = "name"),
        @Result( column = "phone", property = "phone"),
        @Result( column = "wechat", property = "wechat"),
        @Result( column = "recomm", property = "recomm"),
        @Result( column = "photo", property = "photo")}) 
    List<Coach> selectAll() ;

    /** 
     * Select by primary key
     */
    @Select( value = "select * from `coach` where `id` = #{id}") 
    @Results( value = {
        @Result( column = "id", property = "id", id = true),
        @Result( column = "name", property = "name"),
        @Result( column = "phone", property = "phone"),
        @Result( column = "wechat", property = "wechat"),
        @Result( column = "recomm", property = "recomm"),
        @Result( column = "photo", property = "photo")}) 
    Coach selectByPrimaryKey( int id) ;

    @Select( value = "select * from `coach` where phone = #{phone}")
    @Results( value = {
            @Result( column = "id", property = "id", id = true),
            @Result( column = "name", property = "name"),
            @Result( column = "phone", property = "phone"),
            @Result( column = "wechat", property = "wechat"),
            @Result( column = "recomm", property = "recomm"),
            @Result( column = "photo", property = "photo")})
    Coach selectByPhone(String phone);

    /** 
     * Select
     */
    @Select( value = {
        "<script>",
        "select * from `coach`",
        "<where>",
        "<if test='name!=null and name.length>0'> and `name` like '%${name}%'</if>",
        "<if test='phone!=null and phone.length>0'> and `phone` like '%${phone}%'</if>",
        "<if test='wechat!=null and wechat.length>0'> and `wechat` like '%${wechat}%'</if>",
        "<if test='recomm!=null and recomm.length>0'> and `recomm` like '%${recomm}%'</if>",
        "<if test='photo!=null and photo.length>0'> and `photo` like '%${photo}%'</if>",
        "</where>",
        "</script>"}) 
    @Results( value = {
        @Result( column = "id", property = "id", id = true),
        @Result( column = "name", property = "name"),
        @Result( column = "phone", property = "phone"),
        @Result( column = "wechat", property = "wechat"),
        @Result( column = "recomm", property = "recomm"),
        @Result( column = "photo", property = "photo")}) 
    List<Coach> select( Coach coach) ;
}